local NpcState = class("NpcState")

function NpcState:ctor()
    self.uid = ""
    self.id = 0
    self.name = ""
    self.pos = {}
    self.pos.x = 0
    self.map = {}
    self.map.id = 0
    self.map.ownerUid = 0
    self.visibility = ""--enum Visibility {in = 1;      // 进入视野updated = 2; // 更新out = 3;     // 离开视野（走出视野范围，消失，传送等情况）}
end

function NpcState:write(value)
     value.uid = self.uid
     value.id = self.id
     value.name = self.name
     value.pos.x = self.pos.x
     value.map.id = self.map.id
     value.map.ownerUid = self.map.ownerUid
     value.visibility = self.visibility
end


local check = function(v,d)
  if v then
    return v
  else
    return d
  end
end

function NpcState:read(value)
    self.uid = check(value.uid,self.uid)
    self.id = check(value.id,self.id)
    self.name = check(value.name,self.name)
    self.pos.x = check(value.pos.x,self.pos.x)
    self.map.id = check(value.map.id,self.map.id)
    self.map.ownerUid = check(value.map.ownerUid,self.map.ownerUid)
    self.visibility = check(value.visibility,self.visibility)
    -- print("NpcState:read  self.uid = ",self.uid)
    -- print("NpcState:read  self.id = ",self.id)
    -- print("NpcState:read  self.name = ",self.name)
    -- print("NpcState:read  self.pos.x = ",self.pos.x)
    -- print("NpcState:read  self.map.id = ",self.map.id)
    -- print("NpcState:read  self.map.ownerUid = ",self.map.ownerUid)
    -- print("NpcState:read  self.visibility = ",self.visibility)
    local nameLen = string.len(self.name)
   	-- print("NpcState:read  nameLen = ",nameLen)
   	if not self.name or nameLen == 0 then
   		local npcConfig = GD:queryMapNpc(self.id)
   		if npcConfig and npcConfig.name then
   			local name = L(npcConfig.name)
   			self.name = name
   		end
   	end

    self:setUpdate(true)
end

function NpcState:setUpdate(isUpdate)
  self._isUpdate = isUpdate
end

function NpcState:isUpdate()
  return self._isUpdate
end


return NpcState